package com.brush.web.controller.sysnotice;

import com.brush.common.core.controller.BaseController;
import com.brush.common.core.domain.R;
import com.brush.system.domain.req.sysnotice.SysNoticeAddReq;
import com.brush.system.domain.req.sysnotice.SysNoticeEditReq;
import com.brush.system.domain.req.sysnotice.SysNoticeQueryReq;
import com.brush.system.domain.resp.sysnotice.SysNoticeQueryResp;
import com.brush.system.service.SysNoticeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * ClassName: SysNoticeQueryController
 * Package: com.brush.web.controller.sysnoticequery
 * Description:
 *
 * @Author luo
 * @Create 2024/8/23 20:34
 * @Version 1.0
 */
@Api(tags = "后台-公告查询api")
@RestController
@RequestMapping(value = "/admin/notice")
public class SysNoticeController extends BaseController {

    @Autowired
    private SysNoticeService sysNoticeService;


    @PreAuthorize("@ss.hasPermi('system:notice:list')")
    @ApiOperation(value = "分页查询")
    @GetMapping(value = "/list")
    public R<PageInfo<SysNoticeQueryResp>> list(SysNoticeQueryReq req) {
        PageInfo<SysNoticeQueryResp> page = this.sysNoticeService.paginationQuery(req);
        return R.ok(page);
    }

    @ApiOperation(value = "查询详情")
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/{id}")
    public R<SysNoticeQueryResp> findById(@PathVariable(value = "id") Long id) {
        SysNoticeQueryResp resp = this.sysNoticeService.findById(id);
        return R.ok(resp);
    }

    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('system:notice:add')")
    @PostMapping
    public R add(@RequestBody @Valid SysNoticeAddReq req) {
        boolean result = this.sysNoticeService.add(req);
        return super.isSuccess(result);
    }


    @ApiOperation(value = "修改")
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @PutMapping
    public R edit(@RequestBody @Valid SysNoticeEditReq req) {
        boolean result = this.sysNoticeService.edit(req);
        return super.isSuccess(result);
    }

    /**
     * 根据id删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "根据id删除")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
    public R<String> deleteById(@PathVariable(value = "ids") Long[] ids) {
        boolean result = this.sysNoticeService.deleteById(ids);
        return super.isSuccess(result);
    }

}
